package com.nlscan.ncomgateway.core.newland.helper

import android.content.Context
import android.os.Build
import android.os.SystemProperties
import android.provider.Settings
import android.text.TextUtils
import android.util.Log
import com.nlscan.android.scan.ScanManager

/**
 * -- 用于判断设备型号
 * -- 迁移自 迁移自 ScanSettings#
 */
object NlsDeviceHelper {

    fun getScanManagerApiVersionCode(): Int {
        try {
            val scanMgrCls = Class.forName(ScanManager::class.java.name)
            val versionCodeField = scanMgrCls.getDeclaredField("VERSION_CODE")
            if (versionCodeField != null) {
                return versionCodeField[scanMgrCls] as Int
            }
        } catch (e: Exception) {
            Log.w("TAG", "Get api version failed.", e)
        }
        return -1
    }

    fun isNquire300(): Boolean {
        return "NQuire 300" == Build.MODEL || "NQ300" == Build.MODEL
    }

    fun isNquire700(): Boolean {
        println("Build.MODEL=" + Build.MODEL)
        return "NQ700" == Build.MODEL
    }

    fun isNW10(): Boolean {
        return SystemProperties.get("persist.sys.type", "").startsWith("NW10_")
    }

    fun isUseBle(context: Context): Boolean {
        return "BLE" == Settings.Global.getString(context.contentResolver, "currentSensor")
    }

    fun isBLeDevice(sensor: String): Boolean {
        return "外置扫描器" == sensor || "Ext-Scanner" == sensor || "BLE" == sensor
    }

    fun getExtScannerName(context: Context?): String? {
        if (context != null) {
            if (context.resources.configuration.locale.country == "CN") {
                return "外置扫描器"
            }
        }
        return "Ext-Scanner"
    }

    fun isNquire1000(): Boolean {
        return "NQ1000-II" == Build.MODEL || isAndroid10Nquire1000()
    }

    private fun isAndroid10Nquire1000(): Boolean {
        return Build.VERSION.SDK_INT == 29 && "NQ1000" == Build.MODEL
    }

    // nquire android13+
    fun isNLSNQuire(): Boolean {
        return !TextUtils.isEmpty(SystemProperties.get("ro.boot.nquire", ""))
    }
}